package array;

public class L14 {
    public String longestCommonPrefix(String[] strs) {

        if (strs == null || strs.length == 0) {
            return "";
        }
        String init=strs[0];
        int minLength = init.length();

        //找到最短列表的长度
        for (String str :strs){
            if (str.length()<minLength){
                minLength=str.length();
            }
        }
        int end=0;
        for (int i = 0; i < minLength; i++) {
            char c = init.charAt(i);
            for (String str: strs) {
                char c1 = str.charAt(i);
                if (c1 != c){
                    return init.substring(0,end);
                }

            }
            end++;
        }
        return init.substring(0,end);

    }



}
